package com.pang.springcloud.controller;

import com.pang.springcloud.entities.CommonResult;
import com.pang.springcloud.entities.Payment;
import com.pang.springcloud.feignService.FeignService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author： pang-yun
 * @date： 2022-02-11 16:00
 * Description:  接口 + 注解 可以 OpenFeign
 */

@RestController
public class FeignServiceController {

    @Resource
    private FeignService feignService;

    @GetMapping("/consumer/payment/add")
    public CommonResult<Payment> add(Payment payment) {
        return feignService.add(payment);

    }

    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        return feignService.getPaymentById(id);
    }


    /*
     * restTemplate。getForObject 返回对象为响应体数据转化的对象， 基本上可以理解为Json
     * restTemplate.getForEntity  返回对象为ResponseEntity 包含了相应中的一下重要信息 比武 响应头、响应码、响应体等
     * */

    @GetMapping("/consumer/payment/loadBalances")
    public String getPaymentLoadBalances() {
        return feignService.getPaymentLoadBalances();
    }


    //进行OpenFeign 超时测试
    @GetMapping("/consumer/payment/timeout")
    public String getServerPortTimeout(){
        return feignService.getServerPortTimeout();
    }

}
